//
//  RegisterCtr.m
//  iOS
//
//  Created by mokai on 14/11/19.
//  Copyright (c) 2014年 mokai. All rights reserved.
//

#import "RegisterCtr.h"

@interface RegisterCtr ()
@property (nonatomic,strong) UITextField *userNameTextField;
@property (nonatomic,strong) UITextField *passwordTextField;
@property (nonatomic,strong) UITextField *emailTextField;
@end

@implementation RegisterCtr

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title  =@"注册";
    [self setBackItem:@"返回"];
    [self UIInit];
}


-(void)UIInit
{
    UIView *inputBg = [[UIView alloc]initWithFrame:CGRectMake(0, 20, screen_w, 44*3+3)];
    [inputBg setBackgroundColor:[UIColor whiteColor]];
    inputBg.layer.borderColor = sa_color(214, 1.0).CGColor;
    inputBg.layer.borderWidth = 1.0;
    [self.sView addSubview:inputBg];
    //用户名
    UIImageView *userNameFlag = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 14, 14)];
    [userNameFlag setImage:[UIImage imageNamed:@"login_uname.png"]];
    [inputBg addSubview:userNameFlag];
    
    _userNameTextField = [[UITextField alloc]initWithFrame:CGRectMake(40, 0, screen_w-55, 44)];
    _userNameTextField.delegate = self;
    _userNameTextField.tag = 1;
    _userNameTextField.returnKeyType = UIReturnKeyNext;
    _userNameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _userNameTextField.placeholder = [NSString stringWithFormat:@"用户名"];
    _userNameTextField.font = [UIFont systemFontOfSize:14];
    _userNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    
    [inputBg addSubview:_userNameTextField];
    
    UILabel *lineA = [[UILabel alloc]initWithFrame:CGRectMake(15, 44, screen_w-15, 1)];
    lineA.backgroundColor = sa_color(214, 1.0);
    [inputBg addSubview:lineA];
    
    //密码
    UIImageView *passwordFlag = [[UIImageView alloc]initWithFrame:CGRectMake(15, 60, 14, 14)];
    [passwordFlag setImage:[UIImage imageNamed:@"login_pwd.png"]];
    [inputBg addSubview:passwordFlag];
    
    _passwordTextField = [[UITextField alloc]initWithFrame:CGRectMake(40, lineA.bottom, screen_w-55, 44)];
    _passwordTextField.delegate = self;
    _passwordTextField.tag = 2;
    _passwordTextField.returnKeyType = UIReturnKeyNext;
    _passwordTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _passwordTextField.placeholder = [NSString stringWithFormat:@"密码"];
    _passwordTextField.font = [UIFont systemFontOfSize:14];
    _passwordTextField.secureTextEntry = YES;
    _passwordTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [inputBg addSubview:_passwordTextField];
    
    UILabel *lineB = [[UILabel alloc]initWithFrame:CGRectMake(15, _passwordTextField.bottom, screen_w-15, 1)];
    lineB.backgroundColor = sa_color(214, 1.0);
    [inputBg addSubview:lineB];
    
    UIImageView *emailFlag = [[UIImageView alloc]initWithFrame:CGRectMake(15, 105, 14, 14)];
    [emailFlag setImage:[UIImage imageNamed:@"login_phone"]];
    [inputBg addSubview:emailFlag];
    
    _emailTextField = [[UITextField alloc]initWithFrame:CGRectMake(40, lineB.bottom, screen_w-55, 44)];
    _emailTextField.delegate = self;
    _emailTextField.tag = 3;
    _emailTextField.returnKeyType = UIReturnKeySend;
    _emailTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _emailTextField.placeholder = [NSString stringWithFormat:@"邮箱"];
    _emailTextField.font = [UIFont systemFontOfSize:14];
    _emailTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [inputBg addSubview:_emailTextField];
    
    
    UIButton *loginBt = [[UIButton alloc] initWithSystemTheme:CGRectMake(0, inputBg.bottom+20, screen_w-40, 44) title:@"注 册" target:self action:@selector(clickRigest)];
    [self.sView addSubviewToHorizontalCenter:loginBt];
}


-(void)clickRigest{
    if(![self checkData]){
        return;
    }
}

-(bool)checkData{
    if (str_isblank(_userNameTextField.text)) {
        [_userNameTextField becomeFirstResponder];
        [AlertUtils showToast:@"请输入账号"];
        return NO;
    }
    
    if (str_isblank(_passwordTextField.text)) {
        [_userNameTextField becomeFirstResponder];
        [AlertUtils showToast:@"请输入密码"];
        return NO;
    }
    
    if (str_isblank(_emailTextField.text) && [ValidateUtils isEmail:_emailTextField.text]) {
        [_userNameTextField becomeFirstResponder];
        [AlertUtils showToast:@"邮箱格式不正确"];
        return NO;
    }
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}





@end
